package com.xmkj.bearbiz.my.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.common.utils.EmptyUtils;
import com.common.widget.imageview.image.ImageLoaderUtils;
import com.xmkj.bearbiz.R;
import com.xmkj.bearbiz.bean.PicBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/18.
 */

public class PicTabAdapter extends RecyclerView.Adapter<PicTabAdapter.ViewHolder> {
    private ArrayList<PicBean> list;
    private Context context;

    public PicTabAdapter(ArrayList<PicBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_pic, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (EmptyUtils.isNotEmpty(list.get(position).bitPic)) {
            holder.ivImg.setImageBitmap(list.get(position).bitPic);
        } else {
            ImageLoaderUtils.display(holder.ivImg, list.get(position).pic);
        }
        holder.ivImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                picItemClickLisener.onItemClick(position);
            }
        });
    }
    public   interface  PicItemClickLisener{
        void  onItemClick(int position);
    }
    private  PicItemClickLisener picItemClickLisener;
    public  void  setItemClickLister(PicItemClickLisener picItemClickLisener){
        this.picItemClickLisener = picItemClickLisener;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivImg;

        public ViewHolder(View itemView) {
            super(itemView);
            ivImg = (ImageView) itemView.findViewById(R.id.iv_pic);
        }
    }
}
